<?php
App::uses('Component', 'Controller');

class SmsComponent extends Component {
    
    public function sendSMS($msg, $send_no) {

        //return false;//Temporal
        
        if( trim($msg) == "" ) {
            return false;
        }
        //some may bave two numbers so slipt them and use the first one
        $fon_number = '';
        $cell = '';
        if(strpos($send_no,',') !== false){
            $num_arr = explode(',',$send_no);
            $fon_number = trim($num_arr[0]);
        }
        elseif(strpos($send_no,'/') !== false){
            $num_arr = explode('/',$send_no);
            $fon_number = trim($num_arr[0]);
        }
        else{
            $fon_number = trim($send_no);
        }
        //remove the dash separator if any
        $fon_number = preg_replace('/-/', '', $fon_number);
        if(strlen($fon_number) < 9){//not a mobile number
            return false;
        }
        $country_code = substr($fon_number, 0, 3);
        $cell = $fon_number;
        if($country_code != '233'){
           $cell = '233'.substr($fon_number, 1);
        }

        //echo $cell;
        //return;
        //$msg ="Testing";
		//$send_no="0243569192";

       // return;

		$msg = urlencode($msg);
		$url ="http://121.241.242.114:8080/bulksms/bulksms?username=sob-youtong&password=kuulmek&type=0&dlr=1&destination=".$cell."&source=JAPPALERT&message=".$msg;
       // echo $url;
        //http://121.241.242.114:8080/bulksms/bulksms?username=sob-upsa2013&password=123456&type=0&dlr=0&destination=233243569192&source=upsa&message=testing
       // $result = @file_get_contents($url);
        $result = file_get_contents($url);
       // debug($result);
       // $return = true;
       // if($result === false){
         //   $return = false;
       // }
        return $result;
    }
}